package com.exam.demo.controller;

import com.exam.demo.pojo.Student;
import com.exam.demo.pojo.Teacher;
import com.exam.demo.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/teacher")
//管理老师的类
public class TeacherController {
    @Autowired
    private TeacherService teacherService;

    @RequestMapping("/add")
    //老师注册,成功返回1，否则返回0
    private @ResponseBody int add(@RequestBody Teacher teacher){
        return this.teacherService.add(teacher);
    }

    @RequestMapping("/login")
    //老师登录
    private @ResponseBody Boolean login(@RequestParam("teaNo") String teaNo,@RequestParam("teaPwd") String teaPwd){
        return this.teacherService.login(teaNo,teaPwd);
    }

    @RequestMapping("/getinfo")
    private @ResponseBody Teacher getInfo(@RequestParam("teaNo") String teaNo){
        return this.teacherService.getInfo(teaNo);
    }

    @RequestMapping("/changeinfo")
    //老师修改个人资料,成功返回1，否则返回0
    private @ResponseBody int changeInfo(@RequestBody Teacher teacher){
        return this.teacherService.updateTeaInfo(teacher);
    }

    @RequestMapping("/changepwd")
    //老师修改密码,成功返回1，否则返回0
    private @ResponseBody int changePwd(@RequestParam("teaNo") String teaNo,@RequestParam("oldTeaPwd") String oldTeaPwd,@RequestParam("newTeaPwd") String newTeaPwd){
        return this.teacherService.updateTeaPwd(teaNo,oldTeaPwd,newTeaPwd);
    }

    @RequestMapping("/getteabyteano")
    private @ResponseBody List<Teacher> getTeacherListByTeaNo(@RequestParam("teaNo") String teaNo){
        return this.teacherService.getTeacherListByTeaNo(teaNo);
    }

    @RequestMapping("/getteabyteaname")
    private @ResponseBody List<Teacher> getTeacherListByTeaName(@RequestParam("teaName") String teaName){
        return this.teacherService.getTeacherListByTeaName(teaName);
    }

    @RequestMapping("/getteabyteadis")
    private @ResponseBody List<Teacher> getTeacherListByTeaDiscipline(@RequestParam("teaDiscipline") String teaDiscipline){
        return this.teacherService.getTeacherListByTeaDiscipline(teaDiscipline);
    }

    @RequestMapping("/getteabyteamail")
    private @ResponseBody List<Teacher> getTeacherListByTeaMail(@RequestParam("teaMail") String teaMail){
        return this.teacherService.getTeacherListByTeaMail(teaMail);
    }

}
